package org.mspring.mlog.web.query;

import java.util.Map;

import org.mspring.platform.dao.support.query.AbstractQueryCriterion;
import org.mspring.platform.dao.support.query.QueryBuilder;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月22日
 */
@SuppressWarnings("rawtypes")
public class MessageQueryCriterion extends AbstractQueryCriterion {
    private String queryString;
    private String countString;
    private String whereString;

    /**
     * 
     */
    public MessageQueryCriterion(Map queryParams) {
        // TODO Auto-generated constructor stub
        QueryBuilder builder = new QueryBuilder(queryParams);
        builder.startBuild();
        builder.buildEqual("message.readed", "readed", Boolean.class);
        builder.buildEqual("message.sender.id", "sender.id", Long.class);
        builder.buildEqual("message.receiver.id", "receiver.id", Long.class);
        builder.buildLike("message.messageText", "messageText");
        whereString = builder.endBuild();

        namedQueryParams = builder.getNamedQueryParams();
        queryParamsString = builder.getQueryParamsAsString();

        queryString = "select message from Message message ";
        countString = "select count(*) from Message message ";
    }

    @Override
    public String getQueryString() {
        // TODO Auto-generated method stub
        return queryString + whereString;
    }

    @Override
    public String getCountString() {
        // TODO Auto-generated method stub
        return countString + whereString;
    }
}
